package ai.people.netmon.framework.domain.warning.vo;

import ai.people.netmon.framework.businessenum.warning.WarningExportDocumentTypeEnum;
import ai.people.netmon.framework.businessenum.warning.WarningExportDownloadStateEnum;
import ai.people.netmon.framework.businessenum.warning.WarningExportTypeEnum;
import ai.people.netmon.framework.domain.warning.entity.WarningExport;
import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 导出数据
 *
 * @author yuanqinglong
 * @date 2022/7/27 19:07
 */
@Data
public class WarningExportListDataVO {

    /**
     * 报告类型
     */
    private String exportType;

    /**
     * 内容
     */
    private String exportDescription;

    /**
     * 文档类型
     */
    private String exportDocumentType;

    /**
     * 任务时间
     */
    private LocalDateTime exportTime;

    /**
     * 下载状态
     */
    private String exportDownloadStatus;

    /**
     * 用户id
     */
    private Long exportUserId;

    /**
     * 导出文档id
     */
    private String exportDocumentId;

    /**
     * 构建
     *
     * @param warningExport 警告出口
     * @return {@link WarningExportListDataVO}
     */
    public static WarningExportListDataVO build(WarningExport warningExport){
        WarningExportListDataVO warningExportListDataVO = JSON.parseObject(JSON.toJSONString(warningExport), WarningExportListDataVO.class);
        WarningExportTypeEnum warningExportTypeEnum = WarningExportTypeEnum.parseCode(warningExport.getExportType());
        if(warningExportTypeEnum != null){
            warningExportListDataVO.setExportType(warningExportTypeEnum.getName());
        }
        WarningExportDocumentTypeEnum warningExportDocumentTypeEnum = WarningExportDocumentTypeEnum.parseCode(warningExport.getExportDocumentType());
        if(warningExportDocumentTypeEnum != null){
            warningExportListDataVO.setExportDocumentType(warningExportDocumentTypeEnum.getName());
        }
        WarningExportDownloadStateEnum warningExportDownloadStateEnum = WarningExportDownloadStateEnum.parseCode(warningExport.getExportDownloadStatus());
        if(warningExportDownloadStateEnum != null){
            warningExportListDataVO.setExportDownloadStatus(warningExportDownloadStateEnum.getName());
        }
        return warningExportListDataVO;
    }
}
